package com.definity.toolkit.web.taglib;

import javax.servlet.jsp.JspException;

public class OutputTag extends ComponentFormTag {

	private static final long serialVersionUID = -3426306344186292087L;

	private Boolean showEmptyValue;
	
	public OutputTag() {
		setShowEmptyValue(true);
	}

	public void setShowEmptyValue(Boolean showEmptyValue) {
		this.showEmptyValue = showEmptyValue;
	}
	
	@Override
	protected String getComponentName() {
		return "output";
	}
	
	@Override
	protected String createLabel(String id, String label, Object value, FormTag formTag) throws JspException {
		if (!showEmptyValue && valueToString(value).length() == 0)
			return "";
		return super.createLabel(id, label, value, formTag);
	}
	
	@Override
	protected String createStartTag(String name, String id, Object value) throws JspException {
		String valueToString = valueToString(value);
		if (!showEmptyValue && valueToString.length() == 0)
			return "";
		return "<span " + createStyleClass("value") + " id=\"" + id + "\">" + valueToString + "</span>";
	}
	
	@Override
	protected String createEndTag(String name, String id, Object value) {
		return null;
	}
	
}
